home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Chans / fax / ps250 / ps250_manage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  4.9 KB  |  242 lines

  1. /* ps250_manage.c: general management of fax connections */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Chans/fax/ps250/RCS/ps250_manage.c,v 6.0 1991/12/18 20:07:26 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Chans/fax/ps250/RCS/ps250_manage.c,v 6.0 1991/12/18 20:07:26 jpo Rel $
  9.  *
  10.  * $Log: ps250_manage.c,v $
  11.  * Revision 6.0  1991/12/18  20:07:26  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include    "util.h"
  17. #include     "ps250.h"
  18. #include    "retcode.h"
  19. #include    <sys/termios.h>
  20.  
  21. /* 
  22. */
  23.  
  24. int fax_move_and_check (psm, trans)
  25. PsModem *psm;
  26. Trans    *trans;
  27. {
  28.     Stat1    st1;
  29.  
  30.     if (fax_move(psm->fd, trans) == NOTOK) {
  31.         PP_LOG(LLOG_EXCEPTIONS,
  32.                ("fax_move failed"));
  33.         return NOTOK;
  34.     }
  35.     if (fax_getresp (psm->fd, &st1) == NOTOK) {
  36.         PP_LOG(LLOG_EXCEPTIONS,
  37.                ("Bad response from fax"));
  38.         return NOTOK;
  39.     }
  40.     return OK;
  41. }
  42.  
  43. int fax_trans_and_check (psm, trans, listen)
  44. PsModem    *psm;
  45. Trans    *trans;
  46. int    listen;
  47. {
  48.     Stat1    st1;
  49.     int    resp, job;
  50.     int    attempts = 0;
  51.     int    cont = TRUE;
  52.     int    enqSleep = 1;
  53.     psm->connected = FALSE;
  54.  
  55.     for (attempts = 0; attempts < psm->nattempts; attempts++) {
  56.         if (attempts != 0) {
  57.             sleep (psm->sleepFor);
  58.             fax_sendstop(psm->fd);
  59.             fax_getstat1(psm->fd, &st1);
  60.         }
  61.  
  62.         if (fax_trans (psm->fd, trans) == NOTOK) {
  63.             PP_LOG(LLOG_EXCEPTIONS,
  64.                    ("Unable to initialise fax parameters"));
  65.             return NOTOK;
  66.         }
  67.  
  68.         if (listen)
  69.             /* do enq1 elsewhere */
  70.             return OK;
  71.  
  72.         if ((resp = fax_getresp (psm->fd, &st1)) == NOTOK) {
  73.             PP_LOG(LLOG_EXCEPTIONS,
  74.                    ("Bad response from fax"));
  75.             return NOTOK;
  76.         }
  77.  
  78.         if (trans->telno[0] == 0) 
  79.             /* local print so don't wait */
  80.             return OK;
  81.         cont = TRUE;
  82.         while (cont == TRUE && resp == RESP_STAT1) {
  83.  
  84.             switch (job = get_job_info(st1.job_info)) {
  85.                 case JOB_READY:
  86.                 if ((st1.comm & COMM_GMASK) == COMM_G2
  87.                     || (st1.comm & COMM_GMASK) == COMM_G3) {
  88.                     psm->connected = TRUE;
  89.                     return OK;
  90.                 }
  91.                 break;
  92.                 case JOB_IN:
  93.                 break;
  94.                 default:
  95.                 sprintf(psm->errBuf,
  96.                     "Unexpected job info '%d'", job);
  97.                 PP_LOG(LLOG_EXCEPTIONS,
  98.                        ("%s", psm->errBuf));
  99.                 if (st1.fecode[0]) {
  100.                     sprintf(psm->errBuf,
  101.                            "Fax error code: %s",
  102.                            faxerr2str(atoi(st1.fecode)));
  103.                     PP_LOG(LLOG_EXCEPTIONS,
  104.                            ("%s", psm->errBuf));
  105.                 }
  106.                 switch (atoi(st1.fecode)) {
  107.                     case 692:
  108.                     /* busy */
  109.                     cont = FALSE;
  110.                     break;
  111.                     case 690:
  112.                     /* no dial */
  113.                     return NOTOK;
  114.                     default:
  115.                     /* failed */
  116.                     psm->connected = TRUE;
  117.                     return NOTOK;
  118.                 }
  119.             }
  120.             if (cont == TRUE) {
  121.                 sleep (enqSleep);
  122.                 if (fax_sendenq1(psm->fd) == NOTOK) {
  123.                     PP_LOG(LLOG_EXCEPTIONS,
  124.                            ("sendenq1 failed"));
  125.                     return NOTOK;
  126.                 }
  127.                 if ((resp = fax_getresp (psm->fd, &st1)) == NOTOK) {
  128.                     PP_LOG(LLOG_EXCEPTIONS,
  129.                            ("Bad response from fax"));
  130.                     return NOTOK;
  131.                 }
  132.             }
  133.         }
  134.     }
  135.     return NOTOK;
  136. }
  137.  
  138. int fax_revpl_and_check (psm, trans)
  139. PsModem *psm;
  140. Trans    *trans;
  141. {
  142.     Stat1    st1;
  143.     
  144.     if (fax_revpl (psm->fd, trans) == NOTOK) {
  145.         PP_LOG(LLOG_EXCEPTIONS,
  146.                ("Unable to initialise fax parameters"));
  147.         return NOTOK;
  148.     }
  149.  
  150.     if ((fax_getresp (psm->fd, &st1)) == NOTOK) {
  151.         PP_LOG(LLOG_EXCEPTIONS,
  152.                ("Bad response from fax"));
  153.         return NOTOK;
  154.     }
  155.     fax_pstat1(&st1);
  156.     return OK;
  157. }
  158.  
  159. int num_sent;
  160.  
  161. extern char    *get_job_str();
  162.  
  163. int fax_write_and_check (psm, buf, num, flags)
  164. PsModem    *psm;
  165. char    *buf;
  166. int    num, flags;
  167. {
  168.     Stat1    st1;
  169.     int    resp;
  170.  
  171.     if (fax_write (psm->fd, buf, num, flags)) {
  172.         PP_LOG(LLOG_EXCEPTIONS,
  173.                ("fax_write failed"));
  174.         return NOTOK;
  175.     }
  176.     if ((resp = fax_getresp (psm->fd, &st1)) == NOTOK) {
  177.         PP_LOG(LLOG_EXCEPTIONS,
  178.                ("Bad response from fax"));
  179.         return NOTOK;
  180.     }
  181.     if (resp == RESP_ACK) {
  182.         num_sent += num;
  183.         return OK;
  184.     }
  185.     while  (resp == RESP_STAT1) {
  186.         switch (get_job_info(st1.job_info)) {
  187.             case JOB_RETRANS:
  188.             return fax_write_and_check (psm, buf, num, flags);
  189.             case JOB_READY:
  190.             num_sent += num;
  191.             return OK;
  192.             case JOB_IN:
  193.             /* wait and send enq1 */
  194.             if (flags & FAX_WRITE_EOF) 
  195.                 /* do waiting in term fax */
  196.                 return OK;
  197.             sleep (1);
  198.             if (fax_sendenq1(psm->fd) == NOTOK) {
  199.                 PP_LOG(LLOG_EXCEPTIONS,
  200.                        ("sendenq1 failed"));
  201.                 return NOTOK;
  202.             }
  203.             if ((resp = fax_getresp (psm->fd, &st1)) == NOTOK) {
  204.                 PP_LOG(LLOG_EXCEPTIONS,
  205.                        ("Bad response from fax"));
  206.                 return NOTOK;
  207.             }
  208.             break;
  209.             default:
  210.             /* WORK rest of cases */
  211.             PP_LOG(LLOG_EXCEPTIONS,
  212.                    ("fax_write_and_check: Unexpected job info '%s'",
  213.                 get_job_str(st1.job_info)));
  214.             if (st1.fecode[0])
  215.                 PP_LOG(LLOG_EXCEPTIONS,
  216.                        ("Fax error code: %s", 
  217.                     faxerr2str(atoi(st1.fecode))));
  218.  
  219.             return NOTOK;
  220.         }
  221.     }
  222.     return OK;
  223. }
  224.  
  225. int fax_read_and_check (psm, data)
  226. PsModem    *psm;
  227. Data    *data;
  228. {
  229.     if (fax_read (psm->fd, TRUE) == NOTOK) {
  230.         PP_LOG(LLOG_EXCEPTIONS,
  231.                ("fax_read failed"));
  232.         return NOTOK;
  233.     }
  234.     if (fax_data(psm->fd, data) == NOTOK) {
  235.         PP_LOG(LLOG_EXCEPTIONS,
  236.                ("fax_data failed"));
  237.         return NOTOK;
  238.     }
  239.     return OK;
  240. }
  241.  
  242.